package com.centling.smartSealForPhone.activity;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.View;
import android.widget.TextView;

import com.centling.smartSealForPhone.R;
import com.centling.smartSealForPhone.utils.ShowDialog;

import java.util.Locale;

/**
 *
 * @author Jessie
 * @date 2016/9/8
 */
public class AuditorAboutActivity extends TitleBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_auditor_about);
        setTitleBarText("关于章务通定制版");
        TextView version = (TextView) findViewById(R.id.tv_auditor_about_version);
        TextView info = (TextView) findViewById(R.id.tv_company_info);
        SpannableStringBuilder spannable = new SpannableStringBuilder(
                "版权：青岛英泰信息技术有限公司\n服务电话：400-708-9898");
        spannable.setSpan(new TextClick(), 21, 33, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        info.setText(spannable);
        info.setMovementMethod(LinkMovementMethod.getInstance());
        info.setHighlightColor(Color.TRANSPARENT);
        try {
            version.setText(String.format(Locale.CHINA, "当前版本号:%s",
                    getPackageManager().getPackageInfo(getPackageName(), 0).versionName));
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    private class TextClick
            extends ClickableSpan {

        @Override
        public void updateDrawState(TextPaint ds) {
            ds.setColor(ContextCompat.getColor(mContext, R.color.blue1));
        }

        @Override
        public void onClick(View view) {
            ShowDialog.showSelectDialog(mContext, "提示信息", "是否确定拨打电话", "",
                    new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            final String phoneNumber = "400-708-9898";
                            Intent intent = new Intent();
                            intent.setAction(Intent.ACTION_CALL);
                            intent.setData(Uri.parse("tel:" + phoneNumber));
                            startActivity(intent);
                        }
                    });
        }
    }
}
